<?php
/**
 * Created by PhpStorm.
 * User: tangsian
 * Date: 2020/12/18
 * Time: 11:13
 */

namespace App\Http\Model\Api;


use App\Http\Model\Base;
use Illuminate\Support\Facades\DB;

class Union extends Base
{
    protected $table = 'union';
    protected $union_signing_table = 'union_signing';
    protected $connection = "mysql_kkaudio";
    protected $primaryKey = 'id';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    /**
     * 获取用户所签约工会信息
     * @param $userId
     * @return array
     */
    public function getUserUnionSignInfo($userId)
    {
        $condition = [$this->union_signing_table . '.user_id' => $userId];
        $fields = [$this->union_signing_table . '.expire_time', $this->table . '.uuid', $this->union_signing_table . '.user_id'];
        if (is_array($userId)) {
            $result = DB::connection($this->connection)->table($this->union_signing_table)->leftJoin($this->table, $this->table . '.id', '=', $this->union_signing_table . '.un_id')->whereIn('user_id', $userId)->get($fields)->toArray();
            return self::objToArray($result);
        }
        $result = DB::connection($this->connection)->table($this->union_signing_table)->leftJoin($this->table, $this->table . '.id', '=', $this->union_signing_table . '.un_id')->where($condition)->get($fields)->toArray();
        return self::objToArray($result);
    }
}
